<?php
declare(strict_types=1);



/**
 * Class DbMgr
 * @package txz\common\third_lib\model\lib
 */
class DbMgr
{
    /**
     * DbMgr constructor.
     */
    private function __construct()
    {
    }

    private static $connections = [];

    /**
     * @param AbstractTable $table
     * @return mixed
     */
    static function get(AbstractTable &$table){
        $key = $table->getDbName();
        if (!self::hasConnection($key)){
            self::setConnection($key, $table->getConnection($key));
        }
        unset($table);
        return self::$connections[$key];
    }

    /**
     * @param $key
     */
    static function del($key){
        if(self::hasConnection($key))
            unset(self::$connections[$key]);
    }

    /**
     * @param $key
     * @param $con
     */
    static function setConnection($key, $con){
        self::$connections[$key] = $con;
    }

    /**
     * @param $key
     * @return bool
     */
    static function hasConnection($key){
        return isset(self::$connections[$key]);
    }
}